package com.peter.framework.data;

import java.util.Collection;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class DataRetrieveStrategy<T> {

	protected final Logger log = LoggerFactory.getLogger(getClass());

	protected abstract Collection<T> retrieveFromDao() throws Exception;

	protected abstract Collection<T> retrieveFromHttp() throws Exception;

	public Collection<T> call() throws Exception {
		log.debug("createTopics()");

		log.debug("try loading from datasource");
		Collection<T> collection = retrieveFromDao();
		log.trace("collection = {}", collection);
		if (collection == null) {
			log.debug("try loading from http");
			collection = retrieveFromHttp();
		}
		return collection;
	}

}
